var express=require('express');
var app=express();

var request=require('request');
var path = require('path');
var jwt = require('jsonwebtoken');
var expressJWT = require('express-jwt');
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// 设置静态资源管理,可以直接使用localhost:3000/xxx/xxx.png
app.use(express.static(path.join(__dirname, 'public')))

//调试代码
// app.get('/',function(req,res){
//     console.log("页面响应成功");
// })
//

app.all('*', function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
    res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
    res.header("X-Powered-By",' 3.2.1')
    if(req.method=="OPTIONS") res.send(200);/*让options请求快速返回*/
    else  next();
});

var imageBase = 'http://localhost:8888/'

app.get('/api/modules',function(req,res){
    var modules = [
        {title:'热卖',imageUrl:imageBase+'/modules/20180907073509.png'},
        {title:'品牌',imageUrl:imageBase+'/modules/20180907073810.png'},
        {title:'推荐',imageUrl:imageBase+'/modules/20180907073958.png'},
    ]
    res.send(modules);
})

//轮播图数据
app.get('/api/focus',function(req,res){
    var focus = [
        {title:'轮播图0',imageUrl:'http://api.bainhui.com/uploads/g/201808/28/153544633931220.jpg'},
        {title:'轮播图1',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552783910339.jpg'},
        {title:'轮播图2',imageUrl:'http://api.bainhui.com/uploads/g/201808/28/153544637511279.jpg'},
        {title:'轮播图3',imageUrl:'http://api.bainhui.com/uploads/g/201808/28/153544638822308.jpg'},
        {title:'轮播图4',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552785831824.jpg'}

    ]
    res.send(focus);
})

//首页商品分类
app.get('/api/type',function(req,res){
    var type = [
        {title:'鞋靴',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318257565437524.png?x-oss-process=image/resize,w_600,h',typeId:261},
        {title:'食品',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318242240628560.png?x-oss-process=image/resize,w_600,h',typeId:13},
        {title:'箱包',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318258885619958.png?x-oss-process=image/resize,w_600,h',typeId:292},
        {title:'女装',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318245159602702.png?x-oss-process=image/resize,w_600,h',typeId:49},
        {title:'母婴用品',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318260220320424.png?x-oss-process=image/resize,w_600,h',typeId:332},
        {title:'男装',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318246310793365.png?x-oss-process=image/resize,w_600,h',typeId:99},
        {title:'美妆',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318526835248082.png?x-oss-process=image/resize,w_600,h',typeId:358},
        {title:'家居家纺',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318529092437420.png?x-oss-process=image/resize,w_600,h',typeId:387},
        {title:'内衣饰品',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318248774661673.png?x-oss-process=image/resize,w_600,h',typeId:139},
        {title:'日用百货',imageUrl:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/iconUpload/201808/02/153318255164040275.png?x-oss-process=image/resize,w_600,h',typeId:194}
        

    ]
    res.send(type);
})

//热卖1
app.get('/api/hot1',function(req,res){
    var hot1= [
        {title:'品质生活',content:'精致生活,用心选择',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552466460555.jpg',link:'https://api.bainhui.com/wxshare/pages/003/static/'},
        {title:'品质烹饪',content:'完美食生活，烹出好美味',imageUrl:'http://api.bainhui.com/uploads/g/201809/06/153619373598502.jpg',link:'https://api.bainhui.com/wxshare/pages/008/static/'},
    ]
    res.send(hot1);
})

//热卖2
app.get('/api/hot2',function(req,res){
    var hot2= [
        {title:'个性鞋靴',content:'踏出我个性',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552797287451.jpg',link:'https://api.bainhui.com/wxshare/pages/005/static/'},
        {title:'时尚箱包',content:'包罗万箱',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552798552232.jpg',link:'https://api.bainhui.com/wxshare/pages/004/static/'},
        {title:'美容护肌',content:'爱上你的美',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552799579715.jpg',link:'https://api.bainhui.com/wxshare/pages/006/static/'},
        {title:'家用清洁',content:'去污又清新',imageUrl:'http://api.bainhui.com/uploads/g/201809/03/153594710880398.png',link:'https://api.bainhui.com/wxshare/pages/007/static/'},
        {title:'男女配饰',content:'缘来“饰”你',imageUrl:'http://api.bainhui.com/uploads/g/201809/01/153578279622004.jpg',link:'https://api.bainhui.com/wxshare/pages/010/static/'},
        {title:'百变服装',content:'潮流随心选',imageUrl:'http://api.bainhui.com/uploads/g/201809/06/153619383412454.jpg',link:'https://api.bainhui.com/wxshare/pages/002/static/'},
        {title:'运动户外',content:'生命在于运动',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552804131637.jpg',link:'https://api.bainhui.com/wxshare/pages/011/static/'},
        {title:'母婴用品',content:'关爱妈妈宝贝',imageUrl:'http://api.bainhui.com/uploads/g/201808/29/153552805193539.jpg',link:'https://api.bainhui.com/wxshare/pages/009/static/'}
        
        
    ]
    res.send(hot2);
})

//品牌1
app.get('/api/brand1',function(req,res){
    var brand1= [
       {name:'花の物语',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499088376405803.jpg?x-oss-process=image/resize,w_600,h',brandId:120},
       {name:'吉星刀剪厨业',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499654859866683.jpg?x-oss-process=image/resize,w_600,h',brandId:74},
       {name:'凯亚',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499656878518434.jpg?x-oss-process=image/resize,w_600,h',brandId:73},
       {name:'伯尔尼斯',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153500260373831779.jpg?x-oss-process=image/resize,w_600,h',brandId:68},
       {name:'韩纪',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153492862941806787.jpg?x-oss-process=image/resize,w_600,h',brandId:164},
       {name:'冰菊',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153500503140414075.jpg?x-oss-process=image/resize,w_600,h',brandId:50},
       {name:'BINFEIDI/宾妃迪',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499643515309369.jpg?x-oss-process=image/resize,w_600,h',brandId:75},
       {name:'COCODANIE',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153493010570224685.jpg?x-oss-process=image/resize,w_600,h',brandId:144},
       {name:'topesko',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153498972791305160.jpg?x-oss-process=image/resize,w_600,h',brandId:128},
       {name:'瓷肌',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153493042458510402.jpg?x-oss-process=image/resize,w_600,h',brandId:141},
       {name:'福派',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153492890690290566.jpg?x-oss-process=image/resize,w_600,h',brandId:167},
       {name:'碧素堂',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153498992568024490.jpg?x-oss-process=image/resize,w_600,h',brandId:126}    
    ]
    res.send(brand1);
})
//品牌2
app.get('/api/brand2',function(req,res){
    var brand2= [
       {name:'虎哥',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153498858723637110.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'美主人',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/30/153561589395543598.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'罗曼堂',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/30/153561765042082752.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'依姿露',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153492856057315386.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'喜蜜',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153492679566104614.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'superlong世霸龙',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153492626951281401.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'焰狼',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153492950936202614.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'沐晨',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/22/153493020031825672.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'阿明格',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153501102342363397.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'亿米阳光',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499568386094976.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'MELOISION/蜜洛艾森',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499079250068019.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'Secikuf/色彩狂风',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499117783769626.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'庄钰科技',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499171826532443.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'娜维达丝',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499179811821234.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'光度',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499276956160351.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'忆香缘',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/30/153561807839722521.jpg?x-oss-process=image/resize,w_600,h'},
       {name:'虹华达',logo:'http://bnhshop.oss-cn-zhangjiakou.aliyuncs.com/uploads/common/logoUpload/201808/23/153499474815125599.jpg?x-oss-process=image/resize,w_600,h'}
        
        
        
    ]
    res.send(brand2);
})

//获取海量商品数据
app.get('/home',function(req,res){
    res.sendFile(__dirname+'/home.json')
})
//全部商标api
app.get('/allbrand',function(req,res){
    res.sendFile(__dirname+'/allbrand.json')
})
//全部推荐商品
app.get('/allrecommend',function(req,res){
    res.sendFile(__dirname+'/allrecommend.json')
})

// var baseURL = "http://api.caipiao.163.com/missNumber_trend.html?gameEn=";
// app.get('/api/ssq',function(req,res){
//     request(baseURL+"ssq",function(error,response,body){
//          res.send(body);
//     })
// })


app.listen(8888,function(){
    console.log("服务器已经打开");
})
/*
    首先是这么搭建一个服务器的
    1.第一步先 声明两个变量 express app
    var express=require('express');
    var app=express();
    以后的对象都是以app为基准来完成整个服务器的构建
    2.尝试下 服务器是否搭建成功
    app.get('/',function(req,res){
        console.log('页面响应成功');  //在server.js的后台打印
    })
    //这里也就是尝试以下以后将其注释掉

    app.listen(8888,function(){
        console.log('服务器已经成功打开'); //也是在server.js的后台打印
    })
    这里设置了该服务器的接口号 8888
    同时负责监听服务的状态

*/

// 然后第二步要在服务器解决跨域问题
// app.all('*', function(req, res, next) {
//     res.header("Access-Control-Allow-Origin", "*");
//     res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
//     res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//     res.header("X-Powered-By",' 3.2.1')
//     if(req.method=="OPTIONS") res.send(200);/*让options请求快速返回*/
//     else  next();
// });


 


 